﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;

namespace StockAna
{
    public partial class SafeEditForm : Form
    {
        private StockSafe stockSafe;

        public SafeEditForm(StockSafe ss)
        {
            InitializeComponent();

            stockSafe = ss;
            this.Text = ss.name;
            if (string.IsNullOrEmpty(ss.name))
            {
                this.Text = ss.code;
            }
            code.Text = ss.code;

            profit0.DataBindings.Add("Text", ss, "profit0");
            profit_rate.DataBindings.Add("Text", ss, "profit_rate");
            float_asset.DataBindings.Add("Text", ss, "float_asset");
            float_debt.DataBindings.Add("Text", ss, "float_debt");
            depreciation.DataBindings.Add("Text", ss, "depreciation");
            pay.DataBindings.Add("Text", ss, "pay");
            capital.DataBindings.Add("Text", ss, "capital");
            bonus.DataBindings.Add("Text", ss, "bonus");
            refix.DataBindings.Add("Text", ss, "refix");
            note.DataBindings.Add("Text", ss, "note");
            name.DataBindings.Add("Text", ss, "name");

            button2_Click(null, null);
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            stockSafe.Save();
            await SaveHint();
        }

        private async Task<int> SaveHint()
        {
            button1.Text = "...";
            button1.Refresh();
            Thread.Sleep(500);
            button1.Text = "Save";
            button1.Refresh();
            return 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            richTextBox1.Text += string.Format("discount={0}\n", stockSafe.discount);
            richTextBox1.Text += string.Format("safe rate={0}\n\n", stockSafe.safe_rate);

            richTextBox1.Text += string.Format("profit1={0}\n", stockSafe.profit1);
            richTextBox1.Text += string.Format("profit2={0}\n", stockSafe.profit2);
            richTextBox1.Text += string.Format("depreciation={0}\n", stockSafe.depreciation1 + stockSafe.depreciation2);
            richTextBox1.Text += string.Format("bonus={0}\n", stockSafe.bonus2);
            richTextBox1.Text += string.Format("running0={0}\n", stockSafe.running0);
            richTextBox1.Text += string.Format("running2={0}\n", stockSafe.running2);
            richTextBox1.Text += string.Format("run_inc1=-{0}\n", stockSafe.running1_inc);
            richTextBox1.Text += string.Format("run_inc2=-{0}\n", stockSafe.running2_inc);
            richTextBox1.Text += string.Format("pay1=-{0}\n", stockSafe.pay1);
            richTextBox1.Text += string.Format("pay2=-{0}\n", stockSafe.pay2);
            
        }
    }
}
